package org.pix.healthcode; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.preference.PreferenceManager; import android.util.DisplayMetrics; import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.animation.AnimationUtils; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.aztec.encoder.Encoder; import com.google.zxing.common.BitMatrix; import com.google.zxing.pdf417.PDF417Common; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.TimeUnit; public class MainActivity extends Activity implements Handler.Callback, SharedPreferences.OnSharedPreferenceChangeListener, PopupMenu.OnMenuItemClickListener { private static final int MSG_PROMPT_OPTIONS = 1; private static final int MSG_UPDATE_TIME = 0; private PrefsConfig cfg; private Handler handler = null; private Timer promptAnimTimer = null; private SharedPreferences sharedPrefs; private Timer timer = null; /* access modifiers changed from: protected */ public void onCreate(Bundle bundle) { super.onCreate(bundle); this.handler = new Handler(this); this.sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); this.cfg = new PrefsConfig(this); this.cfg.load(); setDisplayLanguage(); } /* access modifiers changed from: protected */ public void onResume() { super.onResume(); setLayout(); updateUI(); this.sharedPrefs.registerOnSharedPreferenceChangeListener(this); AnonymousClass1 r2 = new TimerTask() { /* class org.pix.healthcode.MainActivity.AnonymousClass1 */ public void run() { MainActivity.this.handler.sendEmptyMessage(0); } }; this.timer = new Timer(); this.timer.schedule(r2, 0, 66); if (this.sharedPrefs.getBoolean("KEY_NEWBIE", true)) { this.promptAnimTimer = new Timer(); this.promptAnimTimer.schedule(new TimerTask() { /* class org.pix.healthcode.MainActivity.AnonymousClass2 */ public void run() { MainActivity.this.handler.sendEmptyMessage(MainActivity.MSG_PROMPT_OPTIONS); } }, TimeUnit.SECONDS.toMillis(3), TimeUnit.SECONDS.toMillis(10)); } } /* access modifiers changed from: protected */ public void onPause() { this.timer.cancel(); Timer timer2 = this.promptAnimTimer; if (timer2 != null) { timer2.cancel(); this.promptAnimTimer = null; } this.sharedPrefs.unregisterOnSharedPreferenceChangeListener(this); super.onPause(); } public boolean handleMessage(Message message) { int i = message.what; if (i == 0) { updateDateTimeView(); return false; } else if (i != MSG_PROMPT_OPTIONS) { return false; } else { ((ImageButton) findViewById(R.id.btnOptions)).startAnimation(AnimationUtils.loadAnimation(this, R.anim.prompt_anim)); return false; } } /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */ /* JADX WARNING: Code restructure failed: missing block: B:14:0x004b, code lost: if (r4.equals("KEY_PROVINCE") != false) goto L_0x006d; */ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) { char c = 1; if (str.charAt(str.length() - MSG_PROMPT_OPTIONS) - '0' == this.cfg.getUserIndex()) { String substring = str.substring(0, str.length() - MSG_PROMPT_OPTIONS); switch (substring.hashCode()) { case -2081312997: if (substring.equals("KEY_ID")) { c = 5; break; } c = 65535; break; case -223815079: if (substring.equals("KEY_CONTENT")) { c = 6; break; } c = 65535; break; case -75957343: if (substring.equals("KEY_HOTLINE")) { c = 3; break; } c = 65535; break; case 1231503664: break; case 1312798571: if (substring.equals("KEY_CITY")) { c = 2; break; } c = 65535; break; case 1313118347: if (substring.equals("KEY_NAME")) { c = 4; break; } c = 65535; break; case 2042220867: if (substring.equals("KEY_COLOR")) { c = 0; break; } c = 65535; break; default: c = 65535; break; } switch (c) { case Encoder.DEFAULT_AZTEC_LAYERS: updateQrcode(); updateCheckpoints(); return; case MSG_PROMPT_OPTIONS /*{ENCODED_INT: 1}*/: updateCheckpoints(); return; case 2: updateCityViews(); return; case PDF417Common.MIN_ROWS_IN_BARCODE: updateHotlineView(); return; case 4: updateNameView(); return; case 5: updateIdView(); return; case 6: updateQrcode(); return; default: return; } } } private void updateUI() { updateCityViews(); updateNameView(); updateIdView(); updateQrcode(); updateCheckpoints(); updateHotlineView(); } private void updateCheckpoints() { TextView textView = (TextView) findViewById(R.id.txtCheckpoints); if (textView != null) { String province = this.cfg.getProvince(); String colorName = this.cfg.getColorName(); textView.setText(String.format(this.cfg.getCheckpoint(), colorName, province).concat(getString(R.string.notes))); } } private void updateCityViews() { String province = this.cfg.getProvince(); TextView textView = (TextView) findViewById(R.id.txtTitleCity); if (textView != null) { textView.setText(province); } TextView textView2 = (TextView) findViewById(R.id.txtIdCity); if (textView2 != null) { textView2.setText(province); } } private void updateDateTimeView() { Date date = new Date(); date.setTime(System.currentTimeMillis()); if (findViewById(R.id.txtDateTime) != null) { ((TextView) findViewById(R.id.txtDateTime)).setText(new SimpleDateFormat("MM月dd日 HH:mm:ss", Locale.getDefault()).format(date)); return; } ((TextView) findViewById(R.id.txtMonth)).setText(new SimpleDateFormat("M", Locale.getDefault()).format(date)); ((TextView) findViewById(R.id.txtDay)).setText(new SimpleDateFormat("dd", Locale.getDefault()).format(date)); ((TextView) findViewById(R.id.txtTime)).setText(new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(date)); } private void updateHotlineView() { TextView textView = (TextView) findViewById(R.id.txtHotline); if (textView != null) { textView.setText(this.cfg.getHotline()); } } private void updateNameView() { TextView textView = (TextView) findViewById(R.id.txtUserName); if (textView != null) { textView.setText(this.cfg.getUserName()); } } private void updateIdView() { ToggleButton toggleButton = (ToggleButton) findViewById(R.id.btnIdVisibility); if (toggleButton != null) { boolean isChecked = toggleButton.isChecked(); String userId = this.cfg.getUserId(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < userId.length(); i += MSG_PROMPT_OPTIONS) { sb.append(isChecked ? userId.charAt(i) : '*'); if (i % 4 == 3) { sb.append(' '); } } TextView textView = (TextView) findViewById(R.id.txtIdentityId); if (textView != null) { textView.setText(sb.toString()); } } } private void updateQrcode() { ImageView imageView = (ImageView) findViewById(R.id.imgQrcode); String codeContent = this.cfg.getCodeContent(); int colorValue = this.cfg.getColorValue(); Bitmap genQrcode = genQrcode(codeContent, colorValue); if (genQrcode != null) { imageView.setImageBitmap(genQrcode); } TextView textView = (TextView) findViewById(R.id.txtHospitleTip); if (textView != null) { textView.setTextColor(colorValue); } RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.bgHealthColor); if (relativeLayout != null) { relativeLayout.setBackgroundColor(colorValue); } ImageView imageView2 = (ImageView) findViewById(R.id.qrcode_frame); if (imageView2 != null) { DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); ((GradientDrawable) imageView2.getBackground()).setStroke((int) (displayMetrics.density * 6.0f), colorValue); } } private void setLayout() { String province = this.cfg.getProvince(); if ("杭州".equals(this.cfg.getCity())) { setBrightness(0.618f); setContentView(R.layout.activity_hangzhou); } else if ("山东省".equals(province)) { setBrightness(-1.0f); setContentView(R.layout.activity_sandong); } else { setBrightness(-1.0f); setContentView(R.layout.activity_default); } } public void quit(View view) { finish(); } public void showError(View view) { Toast makeText = Toast.makeText(this, (int) R.string.error, 0); makeText.setGravity(16, 0, 0); makeText.show(); } public void toggleIdNumber(View view) { updateIdView(); } public void switchUser(View view) { this.cfg.setUserIndex((this.cfg.getUserIndex() + MSG_PROMPT_OPTIONS) % 2); setLayout(); updateUI(); } public void refreshQrcode(View view) { updateQrcode(); } public void showOptions(View view) { PopupMenu popupMenu = new PopupMenu(this, view); Menu menu = popupMenu.getMenu(); getMenuInflater().inflate(R.menu.menu, menu); SubMenu subMenu = menu.findItem(R.id.id_customization).getSubMenu(); int i = 0; while (i < 2) { String string = getString(R.string.menu_edit_user); Object[] objArr = new Object[MSG_PROMPT_OPTIONS]; int i2 = i + MSG_PROMPT_OPTIONS; objArr[0] = Integer.valueOf(i2); subMenu.getItem(i).setTitle(String.format(string, objArr)); i = i2; } SubMenu subMenu2 = menu.findItem(R.id.select_language).getSubMenu(); if (this.sharedPrefs.getString("LANGUAGE", Locale.getDefault().getLanguage()).equals(Locale.CHINESE.getLanguage())) { subMenu2.findItem(R.id.id_lang_zh).setChecked(true); } else { subMenu2.findItem(R.id.id_lang_en).setChecked(true); } popupMenu.setOnMenuItemClickListener(this); popupMenu.show(); } public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.id_app_info: WebViewActivity.startActivity(this, (int) R.string.menu_app_info, "file:////android_asset/appinfo.html"); break; case R.id.id_cust1: case R.id.id_cust2: Intent intent = new Intent(this, ConfigActivity.class); intent.putExtra("INDEX", menuItem.getItemId() == R.id.id_cust1 ? 0 : MSG_PROMPT_OPTIONS); startActivity(intent); this.sharedPrefs.edit().putBoolean("KEY_NEWBIE", false).apply(); Timer timer2 = this.promptAnimTimer; if (timer2 != null) { timer2.cancel(); this.promptAnimTimer = null; break; } break; case R.id.id_help_and_suggestion: WebViewActivity.startActivity(this, (int) R.string.menu_help_and_suggestion, "file:////android_asset/help.html"); break; case R.id.id_lang_en: this.sharedPrefs.edit().putString("LANGUAGE", Locale.ENGLISH.getLanguage()).commit(); recreate(); break; case R.id.id_lang_zh: this.sharedPrefs.edit().putString("LANGUAGE", Locale.CHINESE.getLanguage()).commit(); recreate(); break; case R.id.id_privacy: WebViewActivity.startActivity(this, (int) R.string.menu_privacy, "https://morrowind.github.io/privacypolicy/health-code-demo.html"); break; } return false; } private void setDisplayLanguage() { String string = this.sharedPrefs.getString("LANGUAGE", Locale.getDefault().getLanguage()); if (!string.equals(Locale.CHINESE.getLanguage()) && !string.equals(Locale.ENGLISH.getLanguage())) { string = Locale.ENGLISH.getLanguage(); } Locale locale = new Locale(string); Resources resources = getResources(); Configuration configuration = resources.getConfiguration(); configuration.setLocale(locale); resources.updateConfiguration(configuration, resources.getDisplayMetrics()); } private Bitmap genQrcode(String str, int i) { HashMap hashMap = new HashMap(); hashMap.put(EncodeHintType.CHARACTER_SET, "utf-8"); hashMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); hashMap.put(EncodeHintType.MARGIN, 0); try { BitMatrix encode = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, 640, 640, hashMap); int width = encode.getWidth(); int height = encode.getHeight(); int[] iArr = new int[(width * height)]; for (int i2 = 0; i2 < height; i2 += MSG_PROMPT_OPTIONS) { for (int i3 = 0; i3 < width; i3 += MSG_PROMPT_OPTIONS) { iArr[(i2 * width) + i3] = encode.get(i3, i2) ? i : 0; } } Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); createBitmap.setPixels(iArr, 0, width, 0, 0, width, height); return createBitmap; } catch (Exception e) { e.printStackTrace(); return null; } } public void setBrightness(float f) { Window window = getWindow(); WindowManager.LayoutParams attributes = window.getAttributes(); attributes.screenBrightness = f; window.setAttributes(attributes); } }